﻿using CastingWellEquipmentGUI.Config;
using CastingWellEquipmentGUI.Model;
using CastingWellEquipmentGUI.Utils;
using CastingWellEquipmentGUI.ViewModel.Common.Command;
using CastingWellEquipmentGUI.ViewModel.Common.LogTool;
using CastingWellEquipmentGUI.ViewModel.Common.WindowsManager;
using Confluent.Kafka;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;

namespace CastingWellEquipmentGUI.ViewModel.Pages
{
    /// <summary>
    /// 送丝机ViewModel
    /// </summary>
    public class WireFeederPageViewModel : ViewModelBase
    {
        #region 变量/常量
        /// <summary>
        /// 当前窗体名称
        /// </summary>
        private const string showPageTitle = "WireFeederPage";
        /// <summary>
        /// 送丝机手动正转或反正的标识
        /// </summary>
        private bool isForwardRotation = false;
        private Control _CurrentControl;
        /// <summary>
        /// 当前选中的控件
        /// </summary>
        public Control CurrentControl
        {
            get { return _CurrentControl; }
            set { _CurrentControl = value; RaisePropertyChanged("CurrentControl"); }
        }
        #endregion 变量/常量

        #region 页面属性
        private string _Button_CV_RollingSurfaceAirBagPressure;
        /// <summary>
        /// 轧制面气囊压力设定值
        /// </summary>
        public string Button_CV_RollingSurfaceAirBagPressure
        {
            get { return _Button_CV_RollingSurfaceAirBagPressure; }
            set
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_CV_RollingSurfaceAirBagPressure", value))
                {
                    _Button_CV_RollingSurfaceAirBagPressure = value;
                    RaisePropertyChanged("Button_CV_RollingSurfaceAirBagPressure");
                }
            }
        }
        private string _Button_CV_EndAirbagPressure;
        /// <summary>
        /// 端面气囊压力设定值
        /// </summary>
        public string Button_CV_EndAirbagPressure
        {
            get { return _Button_CV_EndAirbagPressure; }
            set
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_CV_EndAirbagPressure", value))
                {
                    _Button_CV_EndAirbagPressure = value;
                    RaisePropertyChanged("Button_CV_EndAirbagPressure");
                }
            }
        }
        private string _Button_CV_WireFeeder;
        /// <summary>
        /// CV值设定
        /// </summary>
        public string Button_CV_WireFeeder
        {
            get
            {
                return _Button_CV_WireFeeder;
            }
            set
            {
                if (KafkaHelper.SendGatewayChangeTagMessage(showPageTitle, "Button_CV_WireFeeder", value))
                {
                    _Button_CV_WireFeeder = value;
                    RaisePropertyChanged("Button_CV_WireFeeder");
                    // 修改成功后刷新PV值即（PV1、PV2）
                    RaisePropertyChanged("Button_WireFeederPV1");
                    RaisePropertyChanged("Button_WireFeederPV2");
                }
            }
        }
        private double _UpperDiscRotationAngle = 0;
        /// <summary>
        /// 上方轮盘旋转角度
        /// </summary>
        public double UpperDiscRotationAngle
        {
            get { return _UpperDiscRotationAngle; }
            set { _UpperDiscRotationAngle = value; RaisePropertyChanged("UpperDiscRotationAngle"); }
        }
        private double _LowerDiscRotationAngle = 0;
        /// <summary>
        /// 下方轮盘旋转角度
        /// </summary>
        public double LowerDiscRotationAngle
        {
            get { return _LowerDiscRotationAngle; }
            set { _LowerDiscRotationAngle = value; RaisePropertyChanged("LowerDiscRotationAngle"); }
        }
        /// <summary>
        /// 送丝机一号轴转速
        /// </summary>
        public string Button_WireFeederPV1
        {
            get { return TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_WireFeederPV1"); }
        }
        /// <summary>
        /// 送丝机二号轴转速
        /// </summary>
        public string Button_WireFeederPV2
        {
            get { return TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_WireFeederPV2"); }
        }
        /// <summary>
        /// 送丝机手动正反转模式设置按钮
        /// </summary>
        public double Button_ManualForwardAndReverseRotation
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_ManualForwardAndReverseRotation") == "true")
                {
                    isForwardRotation = false;
                    return -90;
                }
                else
                {
                    isForwardRotation = true;
                    return 0;
                }
            }
        }
        private Visibility _Button_ManualForwardAndReverseRotationIsEnabled;
        /// <summary>
        /// 手动正反转是否禁用
        /// </summary>
        public Visibility Button_ManualForwardAndReverseRotationIsEnabled
        {
            get { return _Button_ManualForwardAndReverseRotationIsEnabled; }
            set { _Button_ManualForwardAndReverseRotationIsEnabled = value; RaisePropertyChanged("Button_ManualForwardAndReverseRotationIsEnabled"); }
        }
        /// <summary>
        /// 送丝机手自动模式设置按钮
        /// </summary>
        public double Button_ManualAutoMediation
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_ManualAutoMediation") == "false")
                {
                    Button_ManualForwardAndReverseRotationIsEnabled = Visibility.Visible;
                    return -90;
                }
                else
                {
                    Button_ManualForwardAndReverseRotationIsEnabled = Visibility.Hidden;
                    return 0;
                }
            }
        }
        /// <summary>
        /// 送丝机速度设置显示
        /// </summary>
        public string Button_WireFeederSP1
        {
            get { return TagTool.GetTagValueByFormNameAndControlName(showPageTitle, "Button_WireFeederSP1"); }
        }

        #region 控制右侧水滴大小
        private Visibility _Button_EndAirbagPressure_Big_Left_Visibility = Visibility.Hidden;
        public Visibility Button_EndAirbagPressure_Big_Left_Visibility
        {
            get
            {
                return _Button_EndAirbagPressure_Big_Left_Visibility;

            }
            set
            {
                _Button_EndAirbagPressure_Big_Left_Visibility = value;
                RaisePropertyChanged("Button_EndAirbagPressure_Big_Left_Visibility");
            }
        }
        public Visibility Button_EndAirbagPressure_Big_Right_Visibility
        {
            get
            {
                return _Button_EndAirbagPressure_Big_Left_Visibility;

            }
            set
            {
                _Button_EndAirbagPressure_Big_Left_Visibility = value;
                RaisePropertyChanged("Border_EndAirbagPressure_Big_Right_Visibility");
            }
        }

        private Visibility _Button_EndAirbagPressure_Small_Left_Visibility = Visibility.Hidden;
        public Visibility Button_EndAirbagPressure_Small_Left_Visibility
        {
            get
            {
                return _Button_EndAirbagPressure_Small_Left_Visibility;
            }
            set
            {
                _Button_EndAirbagPressure_Small_Left_Visibility = value;
                RaisePropertyChanged("Button_EndAirbagPressure_Small_Left_Visibility");
            }
        }
        public Visibility Button_EndAirbagPressure_Small_Right_Visibility
        {
            get
            {
                return _Button_EndAirbagPressure_Small_Left_Visibility;
            }
            set
            {
                _Button_EndAirbagPressure_Small_Left_Visibility = value;
                RaisePropertyChanged("Border_EndAirbagPressure_Small_Right_Visibility");
            }
        }

        private Visibility _Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility = Visibility.Hidden;
        public Visibility Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility
        {
            get
            {
                return _Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility;
            }
            set
            {
                _Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility = value;
                RaisePropertyChanged("Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility");
            }
        }
        public Visibility Button_RollingSurfaceAirBagPressure_Big_Lower_Visibility
        {
            get
            {
                return _Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility;
            }
            set
            {
                _Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility = value;
                RaisePropertyChanged("Button_RollingSurfaceAirBagPressure_Big_Lower_Visibility");
            }
        }

        private Visibility _Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility = Visibility.Hidden;
        public Visibility Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility
        {
            get
            {
                return _Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility;
            }
            set
            {
                _Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility = value;
                RaisePropertyChanged("Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility");
            }
        }
        public Visibility Button_RollingSurfaceAirBagPressure_Small_Lower_Visibility
        {
            get
            {
                return _Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility;
            }
            set
            {
                _Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility = value;
                RaisePropertyChanged("Button_RollingSurfaceAirBagPressure_Small_Lower_Visibility");
            }
        }
        #endregion 控制右侧水滴大小

        #region 预检测项
        private Visibility _PreDetectionVisibility;
        /// <summary>
        /// 预检测状态
        /// 注：控制预检测框显隐
        /// </summary>
        public Visibility PreDetectionVisibility
        {
            get { return _PreDetectionVisibility; }
            set { _PreDetectionVisibility = value; RaisePropertyChanged("PreDetectionVisibility"); }
        }
        /// <summary>
        /// 轧制面喷射压力正常
        /// </summary>
        public Brush Label_TheSprayPressureOnTheRollingSurfaceIsNormal
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName("WireFeederPage", "Label_TheSprayPressureOnTheRollingSurfaceIsNormal") == "true")
                {
                    return Brushes.Red;
                }
                return Brushes.Black;
            }
        }
        /// <summary>
        /// 端面喷射压力正常
        /// </summary>
        public Brush Label_TheInjectionPressureOnTheEndFaceIsNormal
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName("WireFeederPage", "Label_TheInjectionPressureOnTheEndFaceIsNormal") == "true")
                {
                    return Brushes.Red;
                }
                return Brushes.Black;
            }
        }
        /// <summary>
        /// 送丝机正常
        /// </summary>
        public Brush Label_TheWireFeederIsNormal
        {
            get
            {
                if (TagTool.GetTagValueByFormNameAndControlName("WireFeederPage", "Label_TheWireFeederIsNormal") == "true")
                {
                    return Brushes.Red;
                }
                return Brushes.Black;
            }
        }
        #endregion 预检测项

        #endregion 页面属性

        #region 定义页面执行命令
        /// <summary>
        /// 按钮命令
        /// 按钮1：轧制面气囊压力设定
        /// 按钮2：端面气囊压力设定
        /// </summary>
        public DelegateCommand ShowModalPanelCommand { get; set; }
        /// <summary>
        /// 显示设置自动还是手动窗体命令
        /// </summary>
        public DelegateCommand ShowWireFeederPageSettingPanelCommand { get; set; }
        /// <summary>
        /// 显示设置手动正转还是手动反转窗体命令
        /// </summary>
        public DelegateCommand ShowWireFeederPageSetting1PanelCommand { get; set; }
        /// <summary>
        /// 显示设置SP值窗体命令
        /// </summary>
        public DelegateCommand ShowWireFeederPageSetting2PanelCommand { get; set; }
        /// <summary>
        /// 弹出窗体按钮：送丝机手动正转/反转切换
        /// </summary>
        public DelegateCommand SetSelectControlTagValueCommand { get; set; }
        /// <summary>
        /// 隐藏手动自动切换窗体命令
        /// </summary>
        public DelegateCommand HideFeederPageSettingPanel1WindowCommand { get; set; }
        /// <summary>
        /// 设置选中控件标签值(递增或递减)命令
        /// </summary>
        public DelegateCommand SetSelectControlTagValueByCalculationCommand { get; set; }
        #endregion 定义页面执行命令

        #region 线程对象
        /// <summary>
        /// 动画线程
        /// </summary>
        private Thread animationThread = null;
        /// <summary>
        /// 标签值变化监听线程
        /// </summary>
        private Thread tagInfoSyncThread = null;
        #endregion 线程对象

        #region 方法
        /// <summary>
        /// 构造函数
        /// </summary>
        public WireFeederPageViewModel()
        {
            // 初始化命令
            initCommand();
            // 初始化线程
            initThread();
            // 消息通道注册
            initMessenger();
            // 初始化基础信息
            initBaseSet();
        }

        /// <summary>
        /// 隐藏命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void hideFeederPageSettingPanel1Handler(object obj)
        {
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage(this, "HideFeederPageSettingPanel1"));
        }
        /// <summary>
        /// 初始化基础信息
        /// </summary>
        private void initBaseSet()
        {
            ThreadController.RoundBarWireFeederThreadState = true;
            // 送丝机正反转设定
            for (int i = 0; i < LogTool.CurrentUser.Roles.Count; i++)
            {
                for (int j = 0; j < LogTool.CurrentUser.Roles[i].Permissions.Count; j++)
                {
                    if (LogTool.CurrentUser.Roles[i].Permissions[j].PForm != null &&
                        LogTool.CurrentUser.Roles[i].Permissions[j].PForm.FormName == showPageTitle)
                    {
                        if (LogTool.CurrentUser.Roles[i].Permissions[j].PControl.ControlName == "Button_ManualForwardAndReverseRotation"
                            && LogTool.CurrentUser.Roles[i].Permissions[j].PControl.Tag.Value == "True")
                        {
                            isForwardRotation = true;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 初始化命令
        /// </summary>
        private void initCommand()
        {
            // 轧制面气囊压力设定、端面气囊压力设定
            ShowModalPanelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(showModalPanelHandler)
            };
            // 显示设置手动正转还是手动反转窗体命令
            ShowWireFeederPageSetting1PanelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(showWireFeederPageSetting1PanelHandler)
            };
            // 显示设置自动还是手动窗体命令
            ShowWireFeederPageSettingPanelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(showWireFeederPageSettingPanelHandler)
            };
            // 显示设置SP值窗体命令
            ShowWireFeederPageSetting2PanelCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(showWireFeederPageSetting2PanelHandler)
            };
            // 弹出窗体按钮：手自动切换
            SetSelectControlTagValueCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(setSelectControlTagValueHandler)
            };
            // 弹出窗体按钮：送丝机手动正转/反转切换
            HideFeederPageSettingPanel1WindowCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(hideFeederPageSettingPanel1Handler)
            };
            // 设置选中控件标签值(递增或递减)命令
            SetSelectControlTagValueByCalculationCommand = new DelegateCommand()
            {
                ExecuteActionObj = new Action<object>(setSelectControlTagValueByCalculationHandler)
            };
        }

        /// <summary>
        /// 初始化线程
        /// </summary>
        private void initThread()
        {
            // 动画线程
            animationThread = new Thread(animationThreadFunc);
            animationThread.SetApartmentState(ApartmentState.STA);
            animationThread.IsBackground = true;
            animationThread.Start();

            // 标签值变化监听线程
            tagInfoSyncThread = new Thread(syncThreadFunc);
            tagInfoSyncThread.SetApartmentState(ApartmentState.STA);
            tagInfoSyncThread.IsBackground = true;
            tagInfoSyncThread.Start();
        }

        /// <summary>
        /// 消息通道注册
        /// ViewModel之间数据通信使用，整个项目全局唯一
        /// </summary>
        private void initMessenger()
        {
            //设置Button_CV_WireFeeder的显示值和生产值变更的消息发送给消息队列
            Messenger.Default.Register<string>(this, "SetButton_CV_WireFeeder", (message) =>
            {
                Button_CV_WireFeeder = message.ToString(); ;
            });

            //设置Button_CV_RollingSurfaceAirBagPressure的显示值和生产值变更的消息发送给消息队列
            Messenger.Default.Register<string>(this, "SetButton_CV_RollingSurfaceAirBagPressure", (message) =>
            {
                Button_CV_RollingSurfaceAirBagPressure = message.ToString(); ;
            });

            //设置Button_CV_EndAirbagPressure的显示值和生产值变更的消息发送给消息队列
            Messenger.Default.Register<string>(this, "SetButton_CV_EndAirbagPressure", (message) =>
            {
                Button_CV_EndAirbagPressure = message.ToString(); ;
            });

            //页面切换执行控件刷新
            Messenger.Default.Register<string>(this, "WireFeederPage_DoChange", (message) =>
            {
                HashSet<Control> tempHashSet = SysCommon.getCurrentControl(showPageTitle);
                if (tempHashSet.Count > 0)
                {
                    DoChanged(tempHashSet);
                }
            });
        }

        /// <summary>
        /// 按钮弹框
        /// </summary>
        /// <param name="obj"></param>
        private void showModalPanelHandler(object obj)
        {
            string param = obj.ToString();
            switch (param)
            {
                // CV值设定
                case "Button_CV_WireFeeder":
                    WindowManager.ShowModalDigitalInputPanel("SetCVPanel", "SetButton_CV_WireFeeder", Button_CV_WireFeeder);
                    break;
                // 轧制面气囊压力设定
                case "Button_CV_RollingSurfaceAirBagPressure":
                    WindowManager.ShowModalDigitalInputPanel("SetCVPanel", "SetButton_CV_RollingSurfaceAirBagPressure", Button_CV_RollingSurfaceAirBagPressure);
                    break;
                // 端面气囊压力设定
                case "Button_CV_EndAirbagPressure":
                    WindowManager.ShowModalDigitalInputPanel("SetCVPanel", "SetButton_CV_EndAirbagPressure", Button_CV_EndAirbagPressure);
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 显示设置手动正转还是手动反转窗体命令
        /// </summary>
        /// <param name="obj"></param>
        private void showWireFeederPageSetting1PanelHandler(object obj)
        {
            if (Button_ManualForwardAndReverseRotationIsEnabled == Visibility.Visible)
            {
                return;
            }
            CurrentControl = GetOperation(obj.ToString());
            WindowManager.ShowDialog("WireFeederPageSetting1Panel1Window", null);
        }

        /// <summary>
        /// 显示设置窗体命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void showWireFeederPageSettingPanelHandler(object obj)
        {
            CurrentControl = GetOperation(obj.ToString());
            WindowManager.ShowDialog("WireFeederPageSettingPanel1Window", null);
        }

        /// <summary>
        /// 显示设置SP值窗体命令
        /// </summary>
        /// <param name="obj"></param>
        private void showWireFeederPageSetting2PanelHandler(object obj)
        {
            CurrentControl = GetOperation(obj.ToString());
            WindowManager.ShowDialog("WireFeederPageSetting2Panel1Window", null);
        }

        /// <summary>
        /// 弹出窗体按钮：手自动切换
        /// </summary>
        /// <param name="obj"></param>
        private void setSelectControlTagValueHandler(object obj)
        {
            BusinessCmd setTagValueMsg = new BusinessCmd
            {
                Guid = Guid.NewGuid().ToString(),
                BusinessCmdCode = 3,
                TagId = CurrentControl.Tag.Id,
                TagValue = obj.ToString() == "True" ? "true" : "false"
            };
            // 发送消息
            if (KafkaHelper.SendGatewayBusinessCmd(setTagValueMsg))
            {
                RaisePropertyChanged("Button_ManualAutoMediation");
                RaisePropertyChanged("Button_ManualForwardAndReverseRotation");
            }
        }

        /// <summary>
        /// 获取当前选中控件信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        private Control GetOperation(string param)
        {
            for (int i = 0; i < LogTool.CurrentUser.Roles.Count; i++)
            {
                for (int j = 0; j < LogTool.CurrentUser.Roles[i].Permissions.Count; j++)
                {
                    if (LogTool.CurrentUser.Roles[i].Permissions[j].PForm != null &&
                        LogTool.CurrentUser.Roles[i].Permissions[j].PForm.FormName == showPageTitle &&
                        LogTool.CurrentUser.Roles[i].Permissions[j].PControl != null &&
                        LogTool.CurrentUser.Roles[i].Permissions[j].PControl.ControlName == param)
                    {
                        return LogTool.CurrentUser.Roles[i].Permissions[j].PControl;
                    }
                }
            }
            return null;
        }

        /// <summary>
        /// 动画线程
        /// </summary>
        private void animationThreadFunc()
        {
            while (true)
            {
                if (ThreadController.RoundBarWireFeederThreadState)
                {
                    // 送丝机正转与反转动画控制
                    if (isForwardRotation)
                    {
                        if (UpperDiscRotationAngle < 360)
                        {
                            UpperDiscRotationAngle += 1;
                        }
                        else
                        {
                            UpperDiscRotationAngle = 0;
                            UpperDiscRotationAngle += 1;
                        }
                        if (LowerDiscRotationAngle > -359)
                        {
                            LowerDiscRotationAngle -= 1;
                        }
                        else
                        {
                            LowerDiscRotationAngle = 0;
                            LowerDiscRotationAngle -= 1;
                        }

                    }
                    else
                    {
                        if (LowerDiscRotationAngle < 360)
                        {
                            LowerDiscRotationAngle += 1;
                        }
                        else
                        {
                            LowerDiscRotationAngle = 0;
                            LowerDiscRotationAngle += 1;
                        }
                        if (UpperDiscRotationAngle > -359)
                        {
                            UpperDiscRotationAngle -= 1;
                        }
                        else
                        {
                            UpperDiscRotationAngle = 0;
                            UpperDiscRotationAngle -= 1;
                        }
                    }
                }
                Thread.Sleep(10);
            }
        }

        /// <summary>
        /// 标签值变化监听
        /// </summary>
        private void syncThreadFunc()
        {
            // 创建消费者对象
            IConsumer<string, object> KafkaConsumer = KafkaHelper.GetConsumer();
            while (true)
            {
                if (SystemConfig.systemState == "预检测" || SystemConfig.systemState == "可见许可")
                {
                    PreDetectionVisibility = Visibility.Visible;
                }
                else
                {
                    PreDetectionVisibility = Visibility.Hidden;
                }
                // 网络中断不进行消费监听
                if (SystemConfig.SystemStatus == "网络中断")
                {
                    Thread.Sleep(1000);
                    continue;
                }
                if (ThreadController.RoundBarWireFeederThreadState)
                {
                    //开始消费
                    var result = KafkaConsumer.Consume();
                    if (result != null)
                    {
                        //手动提交
                        KafkaConsumer.Commit(result);
                        //获取消息内容
                        string tagId = result.Message.Value.ToString();
                        HashSet<Control> hashSet = KafkaHelper.UpdateCurrentUserTagValue(Int32.Parse(tagId), KafkaHelper.GetTagValueByKey(tagId.ToString()), showPageTitle);
                        if (hashSet != null)
                        {
                            DoChanged(hashSet);
                        }
                    }
                }
                Thread.Sleep(10);
            }
        }

        /// <summary>
        /// 执行动作
        /// </summary>
        /// <param name="hashSet"></param>
        private void DoChanged(HashSet<Control> hashSet)
        {
            //遍历返回的控件信息刷新对应的控件
            foreach (Control item in hashSet)
            {
                switch (item.ControlName)
                {
                    /** 1、控制页面水滴大小动画 **/
                    case "Button_EndAirbagPressure_Big_Left":
                    case "Border_EndAirbagPressure_Big_Right":
                        //如果是小
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) != "false")
                        {
                            Button_EndAirbagPressure_Big_Left_Visibility = Visibility.Hidden;
                            Button_EndAirbagPressure_Big_Right_Visibility = Visibility.Hidden;
                        }
                        else
                        {
                            Button_EndAirbagPressure_Big_Left_Visibility = Visibility.Hidden;
                            Button_EndAirbagPressure_Big_Right_Visibility = Visibility.Hidden;
                        }
                        break;
                    case "Button_EndAirbagPressure_Small_Left":
                    case "Border_EndAirbagPressure_Small_Right":

                        //如果是大
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "false")
                        {
                            Button_EndAirbagPressure_Small_Left_Visibility = Visibility.Hidden;
                            Button_EndAirbagPressure_Small_Right_Visibility = Visibility.Hidden;
                        }
                        else
                        {
                            Button_EndAirbagPressure_Small_Left_Visibility = Visibility.Visible;
                            Button_EndAirbagPressure_Small_Right_Visibility = Visibility.Visible;
                        }
                        break;
                    case "Button_RollingSurfaceAirBagPressure_Big_Upper":
                    case "Border_RollingSurfaceAirBagPressure_Big_Lower":

                        //如果是小
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) != "false")
                        {
                            Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility = Visibility.Hidden;
                            Button_RollingSurfaceAirBagPressure_Big_Lower_Visibility = Visibility.Hidden;
                        }
                        else
                        {
                            Button_RollingSurfaceAirBagPressure_Big_Upper_Visibility = Visibility.Visible;
                            Button_RollingSurfaceAirBagPressure_Big_Lower_Visibility = Visibility.Visible;
                        }
                        break;
                    case "Button_RollingSurfaceAirBagPressure_Small_Upper":
                    case "Border_RollingSurfaceAirBagPressure_Small_Lower":

                        //如果是大
                        if (TagTool.GetTagValueByFormNameAndControlName(showPageTitle, item.ControlName) == "false")
                        {
                            Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility = Visibility.Hidden;
                            Button_RollingSurfaceAirBagPressure_Small_Lower_Visibility = Visibility.Hidden;
                        }
                        else
                        {
                            Button_RollingSurfaceAirBagPressure_Small_Upper_Visibility = Visibility.Visible;
                            Button_RollingSurfaceAirBagPressure_Small_Lower_Visibility = Visibility.Visible;
                        }
                        break;
                    default:
                        /** 2、刷新页面值变化信息 **/
                        RaisePropertyChanged(item.ControlName);
                        break;
                }
            }
        }

        /// <summary>
        /// 设置选中控件标签值(递增或递减)命令处理器
        /// </summary>
        /// <param name="obj"></param>
        private void setSelectControlTagValueByCalculationHandler(object obj)
        {
            string para = obj.ToString();
            double value = Convert.ToDouble(para.Substring(1));
            TagInfo tagInfo = CurrentControl.Tag;
            double tagVal = KafkaHelper.GetTagDoubleValueByKey(tagInfo.Id.ToString());
            if (para.Contains("+"))
            {
                tagVal += value;
            }
            else if (para.Contains("-"))
            {
                tagVal -= value;
            }
            BusinessCmd setTagValueMsg = new BusinessCmd();
            setTagValueMsg.Guid = Guid.NewGuid().ToString();
            setTagValueMsg.BusinessCmdCode = 3;
            setTagValueMsg.TagId = tagInfo.Id;
            setTagValueMsg.TagValue = tagVal.ToString();

            // 发送消息
            if (KafkaHelper.SendGatewayBusinessCmd(setTagValueMsg))
            {
                RaisePropertyChanged("Button_WireFeederSP1");
            }
        }

        #endregion 方法
    }

}

